﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace SCABaselineCS.Tests.Reliability
{
    [TestClass]
    public class SwitchTests
    {
        public enum Choices { Red, Green, Blue }

        public Choices? CodeSnippet_FallThroughToDefault(Choices choice)
        {
            // minimally, the case for Blue is unnecessary
            // likely, the case for Blue is missing its code and break statement.

            Choices? match = null;
            switch (choice)
            {
                case Choices.Red:
                    match = Choices.Red;
                    break;
                case Choices.Green:
                    match = Choices.Green;
                    break;
                case Choices.Blue:
                default:
                    break;
            }
            return match;
        }
        public bool CodeSnippet_MissingCase(Choices choice)
        {
            bool caseMatched = false;
            switch (choice)
            {
                case Choices.Red:
                    caseMatched = true;
                    break;
                case Choices.Green:
                    caseMatched = true;
                    break;
                default:
                    break;
            }
            return caseMatched;
        }

        [TestMethod]
        public void Test_FallThrough_WhenHandledCorrectly()
        {
            // Arrange

            // Act
            var matchedValue = CodeSnippet_FallThroughToDefault(Choices.Red);

            // Assert
            Assert.IsTrue(matchedValue.HasValue);
            Assert.IsTrue(matchedValue.Value == Choices.Red);
        }

        [TestMethod]
        public void Test_FallThrough_WhenHandledIncorrectly()
        {
            // Arrange

            // Act
            var matchedValue = CodeSnippet_FallThroughToDefault(Choices.Blue);

            // Assert
            Assert.IsFalse(matchedValue.HasValue);
        }

        [TestMethod]
        public void Test_CaseMissing_WhenNotMissing()
        {
            // Arrange

            // Act
            var ChoiceWasFound = CodeSnippet_MissingCase(Choices.Red);

            // Assert
            Assert.IsTrue(ChoiceWasFound);
        }

        [TestMethod]
        public void Test_CaseMissing_WhenMissing()
        {
            // Arrange

            // Act
            var ChoiceWasFound = CodeSnippet_MissingCase(Choices.Blue);

            // Assert
            Assert.IsFalse(ChoiceWasFound);
        }


    } // class
} // namespace